# Install kubernetes

#VPS_PROXY='socks5://192.168.2.3:1081'
VPS_PROXY=''
VPS_PROXY_NULL=""

   
# ##########################################
# # 4.1 pre_pull images
# ##########################################
# # pre_pull images 
# echo "pre_pull images .............."
# sudo docker pull k8s.gcr.io/kube-controller-manager-amd64:v1.11.2
# sudo docker pull k8s.gcr.io/kube-proxy-amd64:v1.11.2
# sudo docker pull k8s.gcr.io/kube-apiserver-amd64:v1.11.2
# sudo docker pull k8s.gcr.io/kube-scheduler-amd64:v1.11.2
# sudo docker pull k8s.gcr.io/kube-proxy-amd64:v1.11.0
# sudo docker pull k8s.gcr.io/kube-controller-manager-amd64:v1.11.0
# sudo docker pull k8s.gcr.io/kube-scheduler-amd64:v1.11.0
# sudo docker pull k8s.gcr.io/kube-apiserver-amd64:v1.11.0
# sudo docker pull k8s.gcr.io/coredns:1.1.3  
# sudo docker pull k8s.gcr.io/etcd-amd64:3.2.18 
# sudo docker pull k8s.gcr.io/pause:3.1 


##########################################
# 5 kubeadm init
##########################################

# Get the IP address that VirtualBox has given this VM
#IPADDR=`ifconfig eth1 | grep Mask | awk '{print $2}'| cut -f2 -d:`
#IPADDR=`ifconfig enp0s8 | grep Mask | awk '{print $2}'| cut -f2 -d:`

IPADDR="192.168.33.10"
echo "This VM has IP address: $IPADDR"
 
export ALL_PROXY=${VPS_PROXY}

# Set up Kubernetes
NODENAME=$(hostname -s)
echo "This VM has IP hostname: $IPADDR"

## kubeadm init --apiserver-cert-extra-sans=$IPADDR  --node-name $N#ODENAME


#kubeadm init --kubernetes-version=1.11.0 --apiserver-cert-extra-sans=$IPADDR  --node-name $NODENAME
sudo kubeadm init --kubernetes-version=1.11.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=$IPADDR \
--node-name=$NODENAME

export ALL_PROXY=${VPS_PROXY_NULL}
# Set up admin creds for the vagrant user
echo Copying credentials to /home/vagrant...
sudo --user=vagrant mkdir -p /home/vagrant/.kube
if [ -f /home/vagrant/.kube/config ]; then
	rm -rf /home/vagrant/.kube/config
fi
sudo cp -if /etc/kubernetes/admin.conf /home/vagrant/.kube/config
sudo chown $(id -u vagrant):$(id -g vagrant) /home/vagrant/.kube/config

sudo tee /root/.bash_aliases <<-"EOF"
export KUBECONFIG=/etc/kubernetes/admin.conf
EOF

export ALL_PROXY=${VPS_PROXY}
#sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
sudo kubectl apply -f ./kube-flannel.yml

# Allow schedule pods on the master
sudo kubectl taint nodes --all node-role.kubernetes.io/master-

# sudo kubeadm reset
